<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        var arr=[10,24,54,23,56,22,36,2,6]

        //冒泡排序(相邻的两个数相比较)
        function bubleSort(arr)    //升序排序
        {
            for(var i=0;i<arr.length;i++)
            {
                for(var j=0;j<arr.length-i-1;j++)
                {
                    if(arr[j]>arr[j+1])
                    {
                        var temp=arr[j]
                        arr[j]=arr[j+1]
                        arr[j+1]=temp
                    }
                }
            }
            return arr;
        }
        console.log(bubleSort(arr));

        function jianSort(arr1)   //降序排序
                {
                    for(var i=0;i<arr1.length;i++)
                    {
                        for(var j=0;j<arr1.length-1-i;j++)
                        {
                            if(arr1[j]<arr1[j+1])
                            {
                                var temp=arr1[j+1];
                                arr1[j+1]=arr1[j];
                                arr1[j]=temp;
                            }
                        }
                    }
                    return arr1;
                }
                console.log(jianSort(arr));

        
    </script>
</head>
<body>
    
</body>
</html>